package com.aosan.website.admin.service.impl

import com.aosan.website.admin.entity.SysRoleEntity
import com.aosan.website.admin.mapper.SysRoleMapper
import com.aosan.website.admin.service.RoleService
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

@Service
class SysRoleServiceImpl : RoleService, ServiceImpl<SysRoleMapper, SysRoleEntity>() {
    val logger = LoggerFactory.getLogger(this::class.java)

    /** 
     * 根据RoleID获取Role名称
     */
    override fun getRolesNameByRoleID(roleID: String): String {
        return this.list(QueryWrapper<SysRoleEntity>()
                .select("description")
                .`in`("role_id", roleID.split(','))).let {
            if (it.size == 0) {
                return ""
            }
            var roles = ""
            for (role in it) roles = roles + role.description + ","
            roles.substring(0, roles.length - 1)
        }
    }

    override fun deleteRole(roleID: Long) {
        this.remove(QueryWrapper<SysRoleEntity>()
                .eq("pid", roleID))
    }

}